package com.invite.me.beans.presenter;

import android.util.Log;


import com.google.gson.Gson;
import com.invite.me.api.UrlConstants;
import com.invite.me.beans.fabean.BlindDataFaBean;
import com.invite.me.beans.fabean.ShimingRzCBean;
import com.invite.me.beans.res.BlindDataFragmentBean;
import com.invite.me.ui.home.fragment.BlindDataFragment;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.invite.me.wlqq.RxJavaDataImpl;

import java.io.IOException;
import java.util.HashMap;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class BlindDataPresenter implements Contract.BasePresenter{


    BlindDataFragment homeActivity;

    public BlindDataPresenter(BlindDataFragment signInActivity) {
        this.homeActivity = signInActivity;
        homeActivity.setPresenter(this);
    }


    @Override
    public void start() {

    }

    //分页查询当前用户附近的人
    public void GengXingerenWz(Double latitude,Double longitude,String name) {
//5b9a7d77312ce909fbab8f65ceea8f50
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        BlindDataFaBean logeInDataBean = new BlindDataFaBean();
        logeInDataBean.setLatitude(latitude+"");
        logeInDataBean.setLongitude(longitude+"");



        Gson gson = new Gson();
        String phoneNumber = gson.toJson(logeInDataBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);

        RxJavaDataImpl.postData(UrlConstants.URL_INVITE_NEAR_BY, hashMap, requestBody, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        BlindDataFragmentBean gankInfo = gson.fromJson(str, BlindDataFragmentBean.class);
                        homeActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                homeActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                homeActivity.onComplete();
            }
        });
    }


    //查询实名认证
    public void shilie(){
        HashMap<String,Object> headrMap = new HashMap<>();
        //  headrMap.put("Content-Type","multipart/form-data");
        headrMap.put("userId",SspPrefUtils.getString(Constants.SSPTOKEN, ""));


        RxJavaDataImpl.getData(UrlConstants.API_SMRZ, headrMap, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        ShimingRzCBean gankInfo = gson.fromJson(str, ShimingRzCBean.class);
                        homeActivity.onDataSucess(gankInfo);

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

}
